package lanqiaobei2013;

public class _全排列 {
    public static void main(String[] args) {
        int[] a = {1,2,3};
        per(a,0,3);
    }
    private static void per(int[] a, int p, int q) {
        if (p == q){
            print(a);
        }else{
            for (int i = p ; i < q ;i ++){
                swap(a,p,i);
                per(a,p+1,q);
                swap(a,p,i);
            }
        }
    }

    private static void swap(int[] a, int p, int i) {
        int temp = a[p];
        a[p] = a[i];
        a[i] = temp;
    }
    private static void print(int[] a) {
        for (int i = 0 ;i <a.length; i ++){
            System.out.print(a[i]);
        }
        System.out.println();
    }
}
